<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const obj = {
        name: 'tu',
        age: 22,
        address: {
          province: '江西',
          city: '南昌',
          county: {
            month: 04,
            day: 28,
          },
        },
      }
      
      let nobj = {}
      function fn(newobj, oldobj) {
        for (let key in oldobj) {
          if (oldobj[key] instanceof Array) {
            newobj[key] = []
            fn(newobj[key], oldobj[key])
          } else if (oldobj[key] instanceof Object) {
            newobj[key] = {}
            fn(newobj[key], oldobj[key])
          } else {
            newobj[key] = oldobj[key]
          }
        }
      }

      fn(nobj, obj)
      obj.age = 20
      console.log(obj)
      console.log(nobj)
    </script>
  </body>
</html>
